/****************************
* probe ucosii to help2416 
* a simple test app file
* author: qingluo
* date: april-22-2013
* version: v1.0
*****************************/

#include <includes.h>
#include <ucos_ii.h>
#include <timer.h>
#include <irq.h>

#define TASK_STK_SIZE		1024
OS_STK appstarttask_stack[TASK_STK_SIZE];

void AppStartTask(void *data);
void MMU_EnableDCache(void);
void MMU_EnableICache(void);
void exception_vector(void);

void ledoff(void);
void ledon(void);

void BSP_init(void)
{
	timer_0_init();
	Uart_0_Init();
}

int Main(void)
{
	//BSP_IntDisAll(); use irq_init
	inerrupt_vector_init();
	BSP_init();
	OS_MemCopy((INT8U *)0xffff0000, (INT8U *)(exception_vector), 128);
	Uart_Printf("*************************************\n");
	Uart_Printf("*            qingluo's super ucosii *\n");
	Uart_Printf("*                 VERSION 1.0		*\n");
	Uart_Printf("*                    WELCOME		*\n");
	Uart_Printf("* HCLK:				 *\n");
	Uart_Printf("*************************************\n");
	MMU_EnableDCache();
	MMU_EnableICache();	
	Uart_Printf("Start OS init!\n");
	OSInit();

	OSTaskCreate(AppStartTask, (void *)10, &appstarttask_stack[TASK_STK_SIZE - 1], 1);
	
	OSStart();
	return 0;
}

void AppStartTask(void *data)
{
	data = data;
	//OS_CPU_SysTickInit(); equal to timer_0_init()
#if OS_TASK_STAT_EN > 0
	//OSStatInit();
#endif
	//AppTaskCreate();	//create user app task in this function
	for(;;)
    	{
		//LED_Toggle(1);
		Uart_Printf("A\n");
		OSTimeDly(OS_TICKS_PER_SEC);
    	}
}
